import axios from 'axios'
import nProgress from 'nprogress'
import 'nprogress/nprogress.css'
import store from '@/store'

const instance = axios.create({
  // 在这里引入基础url，后面的接口拼接在baseURL
  baseURL: 'http://likede2-admin.itheima.net/likede',
  timeout: 5000
})

instance.interceptors.request.use(config => {
  // 调用请求条
  nProgress.start()

  const token = store.state.token
  config.headers.Authorization = `${token}`
  return config
}, err => {
  return Promise.reject(err)
})

instance.interceptors.response.use(res => {
  // 请求条结束
  nProgress.done()
  return res.data
}, err => {
  return Promise.reject(err)
})

export default instance
